const fs = require('fs')
const path = require('path')

// fs.readFile(path.join(__dirname,'test333'),(err,data)=>{

//     if(err) {
//         throw err;
//         return false;
//     }
//     fs.writeFile(path.join(__dirname,'test44'),data,(err)=>{
//         if(err) throw err;
//      })
// })



var reader = fs.createReadStream(path.join(__dirname,'test333'),{encoding:'utf8',start:0,end:10})

var writer = fs.createWriteStream(path.join(__dirname,'test444'));

fs.stat(path.join(__dirname,'test333'),(err,stats)=>{

    if(err) {
        throw err;
       
    }

    if(stats){
        var readTotal = 0;
        reader.on('data',(chunk)=>{
            // console.log(chunk.length);
            writer.write(chunk,(err)=>{
                if(err) throw err;
                console.log('写进度:'+((readTotal+=chunk.length)/stats.size*100)+'%')
            })
        })

       
    }
})

